package cn.tedu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller //标识此类为controller层,并且创建对象交给Spring容器管理
public class HelloController {

    //http://localhost:8080/hello
    @RequestMapping("hello") //访问路径
    public String doHelloUI() {
        //返回给调用方,这里是DispatcherServlet,DispatcherServlet会将hello字符串交给视图解析器,
        //thymeleaf中的视图解析器会对hello字符串添加前缀和后缀,返回的是页面
        return "hello";
    }

    //http://localhost:8080/doSayHello
    @RequestMapping("doSayHello")
    @ResponseBody //告诉SpringMVC框架返回值不是view,而是具体的数据
    public String doSayHello() {
        //返回的是数据
        return "Hello SpringMVC!";
    }
}
